var app = getApp();
Page({
    data: {
        //button状态
        showView: true,
        //被查看用户账号
        Phone1: null,
        //用户本身账号
        phone2: null,
        userInfo: {},
        hasUserInfo: false,
        canIUseGetUserProfile: false,
    },
    onLoad: function (options) {
        if (wx.getUserProfile) {
            this.setData({
                canIUseGetUserProfile: true
            })
        }
    },
    getUserProfile(e) {
        // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认
        // 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
        wx.getUserProfile({
            desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
            success: (res) => {
                this.setData({
                    userInfo: res.userInfo,
                    hasUserInfo: true
                })
            }
        })
    },
    getUserInfo(e) {
        // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
        this.setData({
            userInfo: e.detail.userInfo,
            hasUserInfo: true
        })
    },
    onReady: function () {
        var appData = app.appData;
        var systemUser = appData.systemUser;
        var phone2 = systemUser.phone;
        var ststus = systemUser.status;
        var userInfo = this.data.userInfo
        //临时注销下，记得注销回来
        /*     if (ststus == "未登录") {
              wx.redirectTo({
                url: '../login_index/login_index',
              })
            } */
        //获取头像和昵称


//
        this.setData({
            phone2: phone2,
            userInfo: app.globalData.userInfo
        });

    },
    radioChange: function (e) {
        console.log('radio发生change事件，携带value值为：', e.detail.value)
    },

    chakan: function () {
        var phone1 = this.data.phone1;
        var phone2 = this.data.phone2;
        var that = this;
        if (phone1 == null) {
            wx.showToast({
                title: '账号不能为空',
                icon: 'loading',
                duration: 500
            })
        } else {
            wx.request({
                url: app.appData.contextPath + 'permissionServlet',
                data: {
                    phone1: phone1
                },
                header: {
                    'content-type': 'application/json' // 默认值
                },
                success: function (res) {
                    console.info(res)
                    var fPhone = res.data
                    var phone2 = that.data.phone2
                    var phone1 = that.data.phone1
                    if (fPhone == phone2 || phone1 == phone2) {
                        wx.navigateTo({
                            url: '../../pages/location_item/location?phone=' + phone1
                        })
                    } else {

                        wx.showToast({
                            title: '您没有权限访问',
                            icon: 'loading',
                            duration: 500
                        })
                    }
                },
                fail: function () {

                }
            })
        }
    },

    phoneinput: function (e) {
        var phone1 = e.detail.value
        this.setData({
            phone1: phone1
        });
    },
    shareRoad: function () {
        wx.navigateTo({
            url: '../../pages/shareRoad/shareRoad',
        })
    },
    historyTrail: function () {
        wx.navigateTo({
            url: '../../pages/historyTrail/historyTrail',
        })
    },
    designTrail: function () {
        wx.navigateTo({
            url: '../../pages/designTrail/designTrail',
        })
    },
    messageTrail: function () {
        wx.navigateTo({
            url: '../../pages/receviveMessage/receviveMessage',
        })
    },
    //绑定车票查询按钮事件
    check: function (e) {

        wx.navigateTo({
            url: '../Ticket_index/Ticlet_index',
        })
    },
    // 机票查询页面
    goPlaneTicket:()=>{
      wx.navigateTo({
          url:'../planeTicket/planeTicket'
      })
    },
    //获取用户信息
    getUserInfo: function (e) {
        this.setData({
            userInfo: e.detail.userInfo
        });
        console.info(e)
    },
    hide: function () {
        this.setData({
            showView: false
        });
    }
})
